package com.atguigu.oshiapp.oshiapp.service;

import org.springframework.stereotype.Service;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.HardwareAbstractionLayer;

/**
 * @Author: Mouoal
 * @CreateTime: 2025-01-06  23:14
 * @Version: 1.0
 */
@Service
public class CpuLoadMetricsService {

    //OSHI 提供的获取所有数据的入口
    SystemInfo si = new SystemInfo();
    public double[] getCpuLoad(){

        HardwareAbstractionLayer hardware = si.getHardware();
        CentralProcessor processor = hardware.getProcessor();
        //统计1s内的使用率，所以阻塞一秒
        double[] cpuLoad = processor.getProcessorCpuLoad(1000);

        return cpuLoad;
    }
}
